﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using FrienDev.BusinessRules;
using FrienDev.Data;
using System.Collections.Generic;

public partial class Controls_Club_InfoDetail : System.Web.UI.UserControl
{

    private static int m_ClubId = -1;
    protected void Page_Load(object sender, EventArgs e)
    {
        Club club = null;
        if (HttpContext.Current.Request["clubId"] != null)
        {
            m_ClubId = Convert.ToInt32(HttpContext.Current.Request["clubId"]);
        }
        if (m_ClubId != -1)
        {
            club = ClubRules.Instance.GetClubByClubId(m_ClubId);
            IEnumerable<ClubMember> m_ClubInfo = ClubRules.Instance.GetCurrentUserInfo(m_ClubId);
            if (m_ClubInfo.Count() > 0)
            {
                join.Visible = false;
                arrow.Visible = false;
                //if ((m_ClubInfo.First()).ClubMemberTypeId == ClubRules.m_1LevelMemberTypeId)
                //{
                //    edit.Visible = true;
                //}
            }
        }
        if (club != null)
        {
            clubName.Text = club.ClubName;
            clubName2.Text = "俱乐部："+club.ClubName;
            clubDes.ToolTip = club.Description;
            clubDes.Text = club.Description; //HtmlHelper.InterceptSubString(club.Description, 20, true);
            position.Text = club.City.CityName;
            clubHead.Text = ClubRules.Instance.GetClubHeadByClubId(club.ClubId);
            membersAmount.Text = ClubRules.Instance.GetClubMemberAmountByClubId(club.ClubId).ToString();
            //clubType.Text = club.ClubType.ToString();
            //createDate.Text = club.CreateDate.ToShortDateString();
            //privacy.Text = club.PrivacyType.ToString();
            logo.ImageUrl = "/upload/club/" + club.LogoFileName;
            //edit.NavigateUrl = edit.NavigateUrl + "?clubId=" + m_ClubId;
        }
    }
    protected void join_Click(object sender, EventArgs e)
    {
        if (!ClubRules.Instance.GetClubByClubId(m_ClubId).AddRule)
        {
            ClubRules.Instance.AddClubMember(m_ClubId, UserRules.Instance.GetCurrentUserId(), DateTime.Now, ClubRules.m_3LevelMemberTypeId);
            //Page.ClientScript.RegisterStartupScript(this.GetType(), "myscript", "javascript:alert('已成功加入该俱乐部');", true);
        }
        else
        {
            ClubRules.Instance.AddClubMember(m_ClubId, UserRules.Instance.GetCurrentUserId(), DateTime.Now, ClubRules.m_4LevelMemberTypeId);
            //Page.ClientScript.RegisterStartupScript(this.GetType(), "myscript", "javascript:alert('已递交申请,请等待批准');", true);
            //remind.Visible = true;
        }
        Response.Redirect("/Club/Detail.aspx?clubId=" + m_ClubId);
    }
}
